home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 1.iso / dist / fw_apache2.idb / usr / freeware / apache2 / include / apr_lib.h.z / apr_lib.h
C/C++ Source or Header  |  2002-07-08  |  9KB  |  260 lines

  1. /* ====================================================================
  2.  * The Apache Software License, Version 1.1
  3.  *
  4.  * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
  5.  * reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  *
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  *
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in
  16.  *    the documentation and/or other materials provided with the
  17.  *    distribution.
  18.  *
  19.  * 3. The end-user documentation included with the redistribution,
  20.  *    if any, must include the following acknowledgment:
  21.  *       "This product includes software developed by the
  22.  *        Apache Software Foundation (http://www.apache.org/)."
  23.  *    Alternately, this acknowledgment may appear in the software itself,
  24.  *    if and wherever such third-party acknowledgments normally appear.
  25.  *
  26.  * 4. The names "Apache" and "Apache Software Foundation" must
  27.  *    not be used to endorse or promote products derived from this
  28.  *    software without prior written permission. For written
  29.  *    permission, please contact apache@apache.org.
  30.  *
  31.  * 5. Products derived from this software may not be called "Apache",
  32.  *    nor may "Apache" appear in their name, without prior written
  33.  *    permission of the Apache Software Foundation.
  34.  *
  35.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38.  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46.  * SUCH DAMAGE.
  47.  * ====================================================================
  48.  *
  49.  * This software consists of voluntary contributions made by many
  50.  * individuals on behalf of the Apache Software Foundation.  For more
  51.  * information on the Apache Software Foundation, please see
  52.  * <http://www.apache.org/>.
  53.  */
  54.  
  55. #ifndef APR_LIB_H
  56. #define APR_LIB_H
  57. /**
  58.  * @file apr_lib.h
  59.  * @brief APR general purpose library routines
  60.  */
  61.  
  62. #include "apr.h"
  63. #include "apr_errno.h"
  64.  
  65. #if APR_HAVE_CTYPE_H
  66. #include <ctype.h>
  67. #endif
  68. #if APR_HAVE_STDARG_H
  69. #include <stdarg.h>
  70. #endif
  71. /**
  72.  * @defgroup APR_General General Purpose Library Routines
  73.  * @ingroup APR
  74.  * @{
  75.  */
  76.  
  77. #ifdef __cplusplus
  78. extern "C" {
  79. #endif /* __cplusplus */
  80.  
  81. #define HUGE_STRING_LEN 8192
  82.  
  83. /*
  84.  * Define the structures used by the APR general-purpose library.
  85.  */
  86.  
  87. typedef struct apr_vformatter_buff_t apr_vformatter_buff_t;
  88.  
  89. /**
  90.  * Structure used by the variable-formatter routines.
  91.  */
  92. struct apr_vformatter_buff_t {
  93.     /** The current position */
  94.     char *curpos;
  95.     /** The end position of the format string */
  96.     char *endpos;
  97. };
  98.  
  99. /**
  100.  * return the final element of the pathname
  101.  * @param pathname The path to get the final element of
  102.  * @return the final element of the path
  103.  * @example
  104.  */
  105. /**
  106.  * Examples:
  107.  * <PRE>
  108.  *                 "/foo/bar/gum"   -> "gum"
  109.  *                 "/foo/bar/gum/"  -> ""
  110.  *                 "gum"            -> "gum"
  111.  *                 "wi\\n32\\stuff" -> "stuff"
  112.  * </PRE>
  113.  */
  114. APR_DECLARE(const char *) apr_filename_of_pathname(const char *pathname);
  115.  
  116. /**
  117.  * These macros allow correct support of 8-bit characters on systems which
  118.  * support 8-bit characters.  Pretty dumb how the cast is required, but
  119.  * that's legacy libc for ya.  These new macros do not support EOF like
  120.  * the standard macros do.  Tough.
  121.  * @defgroup apr_ctype ctype functions
  122.  * @{
  123.  */
  124. /** @see isalnum */
  125. #define apr_isalnum(c) (isalnum(((unsigned char)(c))))
  126. /** @see isalpha */
  127. #define apr_isalpha(c) (isalpha(((unsigned char)(c))))
  128. /** @see iscntrl */
  129. #define apr_iscntrl(c) (iscntrl(((unsigned char)(c))))
  130. /** @see isdigit */
  131. #define apr_isdigit(c) (isdigit(((unsigned char)(c))))
  132. /** @see isgraph */
  133. #define apr_isgraph(c) (isgraph(((unsigned char)(c))))
  134. /** @see islower*/
  135. #define apr_islower(c) (islower(((unsigned char)(c))))
  136. /** @see isascii */
  137. #ifdef isascii
  138. #define apr_isascii(c) (isascii(((unsigned char)(c))))
  139. #else
  140. #define apr_isascii(c) (((c) & ~0x7f)==0)
  141. #endif
  142. /** @see isprint */
  143. #define apr_isprint(c) (isprint(((unsigned char)(c))))
  144. /** @see ispunct */
  145. #define apr_ispunct(c) (ispunct(((unsigned char)(c))))
  146. /** @see isspace */
  147. #define apr_isspace(c) (isspace(((unsigned char)(c))))
  148. /** @see isupper */
  149. #define apr_isupper(c) (isupper(((unsigned char)(c))))
  150. /** @see isxdigit */
  151. #define apr_isxdigit(c) (isxdigit(((unsigned char)(c))))
  152. /** @see tolower */
  153. #define apr_tolower(c) (tolower(((unsigned char)(c))))
  154. /** @see toupper */
  155. #define apr_toupper(c) (toupper(((unsigned char)(c))))
  156. /** @} */
  157. /**
  158.  * apr_killpg
  159.  * Small utility macros to make things easier to read.  Not usually a
  160.  * goal, to be sure..
  161.  */
  162.  
  163. #ifdef WIN32
  164. #define apr_killpg(x, y)
  165. #else /* WIN32 */
  166. #ifdef NO_KILLPG
  167. #define apr_killpg(x, y)        (kill (-(x), (y)))
  168. #else /* NO_KILLPG */
  169. #define apr_killpg(x, y)        (killpg ((x), (y)))
  170. #endif /* NO_KILLPG */
  171. #endif /* WIN32 */
  172.  
  173. /**
  174.  * apr_vformatter() is a generic printf-style formatting routine
  175.  * with some extensions.
  176.  * @param flush_func The function to call when the buffer is full
  177.  * @param c The buffer to write to
  178.  * @param fmt The format string
  179.  * @param ap The arguments to use to fill out the format string.
  180.  *
  181.  * @example 
  182.  */
  183. /**
  184.  * <PRE>
  185.  * The extensions are:
  186.  *
  187.  * %%pA    takes a struct in_addr *, and prints it as a.b.c.d
  188.  * %%pI    takes an apr_sockaddr_t * and prints it as a.b.c.d:port or
  189.  *      [ipv6-address]:port
  190.  * %%pp takes a void * and outputs it in hex
  191.  *
  192.  * The %%p hacks are to force gcc's printf warning code to skip
  193.  * over a pointer argument without complaining.  This does
  194.  * mean that the ANSI-style %%p (output a void * in hex format) won't
  195.  * work as expected at all, but that seems to be a fair trade-off
  196.  * for the increased robustness of having printf-warnings work.
  197.  *
  198.  * Additionally, apr_vformatter allows for arbitrary output methods
  199.  * using the apr_vformatter_buff and flush_func.
  200.  *
  201.  * The apr_vformatter_buff has two elements curpos and endpos.
  202.  * curpos is where apr_vformatter will write the next byte of output.
  203.  * It proceeds writing output to curpos, and updating curpos, until
  204.  * either the end of output is reached, or curpos == endpos (i.e. the
  205.  * buffer is full).
  206.  *
  207.  * If the end of output is reached, apr_vformatter returns the
  208.  * number of bytes written.
  209.  *
  210.  * When the buffer is full, the flush_func is called.  The flush_func
  211.  * can return -1 to indicate that no further output should be attempted,
  212.  * and apr_vformatter will return immediately with -1.  Otherwise
  213.  * the flush_func should flush the buffer in whatever manner is
  214.  * appropriate, re apr_pool_t nitialize curpos and endpos, and return 0.
  215.  *
  216.  * Note that flush_func is only invoked as a result of attempting to
  217.  * write another byte at curpos when curpos >= endpos.  So for
  218.  * example, it's possible when the output exactly matches the buffer
  219.  * space available that curpos == endpos will be true when
  220.  * apr_vformatter returns.
  221.  *
  222.  * apr_vformatter does not call out to any other code, it is entirely
  223.  * self-contained.  This allows the callers to do things which are
  224.  * otherwise "unsafe".  For example, apr_psprintf uses the "scratch"
  225.  * space at the unallocated end of a block, and doesn't actually
  226.  * complete the allocation until apr_vformatter returns.  apr_psprintf
  227.  * would be completely broken if apr_vformatter were to call anything
  228.  * that used a apr_pool_t.  Similarly http_bprintf() uses the "scratch"
  229.  * space at the end of its output buffer, and doesn't actually note
  230.  * that the space is in use until it either has to flush the buffer
  231.  * or until apr_vformatter returns.
  232.  * </PRE>
  233.  */
  234. APR_DECLARE(int) apr_vformatter(int (*flush_func)(apr_vformatter_buff_t *b),
  235.                     apr_vformatter_buff_t *c, const char *fmt,
  236.                     va_list ap);
  237.  
  238. /**
  239.  * Validate any password encypted with any algorithm that APR understands
  240.  * @param passwd The password to validate
  241.  * @param hash The password to validate against
  242.  */
  243. APR_DECLARE(apr_status_t) apr_password_validate(const char *passwd, 
  244.                                                 const char *hash);
  245.  
  246. /**
  247.  * Display a prompt and read in the password from stdin.
  248.  * @param prompt The prompt to display
  249.  * @param pwbuf Buffer to store the password
  250.  * @param bufsize The length of the password buffer.
  251.  */
  252. APR_DECLARE(apr_status_t) apr_password_get(const char *prompt, char *pwbuf, 
  253.                                            size_t *bufsize);
  254.  
  255. #ifdef __cplusplus
  256. }
  257. #endif
  258. /** @} */
  259. #endif    /* ! APR_LIB_H */
  260.